package com.hs.myshell.data;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.ui.internal.UIPlugin;

import com.hs.myshell.views.tree.TreeObject;

/**
 * 统一的数据操作对象
 * @author Administrator
 * @see https://www.runoob.com/design-pattern/singleton-pattern.html
 *
 */
public class DataAccess {
	
	private Map<String,SshSetting> data = new ConcurrentHashMap<>();
	
	private volatile static DataAccess dataAccess;  
    private DataAccess (){}  
    public static DataAccess getInstance() {  
	    if (dataAccess == null) {  
	        synchronized (DataAccess.class) {  
	        if (dataAccess == null) {  
	            dataAccess = new DataAccess();  
	        }  
	        }  
	    }  
	    return dataAccess;  
    }
    public void init() {
    	SshSetting oneSshSetting = new SshSetting();
    	oneSshSetting.setHost("192.168.4.110");
		//TODO load data from disk or server
    	data.put(oneSshSetting.getHost(), oneSshSetting);
    }
	public SshSetting get(TreeObject sshKey) {
		// load setting by 
		if(sshKey != null) {
			return data.get(sshKey.getName());
		}else {
			return new SshSetting();
		}
	}
	public void saveOrUpdate(SshSetting sshSetting) {
//		UIPlugin.getDefault().getLog().log();
		System.out.println("save config to persis");
		
		
	}  

}
